<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 200px;
            height: 200px;
            background-color: #6ff;
            margin: 50px;
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>
<script>

    var box = document.getElementsByClassName("box")[0];

    // onmouseover 鼠标划入元素时触发
    box.onmouseover = function () {
        console.log("鼠标划入box");
        this.style.backgroundColor = "red";
    }

    // onmouseout 鼠标划出元素时触发
    box.onmouseout = function () {
        console.log("鼠标划出box");
        this.style.backgroundColor = "#6ff";
    }


</script>

</html>